

            function set_cookie(my_cookie, value, days) {
                if (days) {
                    var date = new Date();
                    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
                    var expires = "; expires=" + date.toGMTString();
                }
                else
                    expires = "";
                document.cookie = my_cookie + "=" + value + expires + "; path=/";
            }


            function read_cookie(my_cookie) {
                var my_cookie_eq = my_cookie + "=";
                var ca = document.cookie.split(';');
                for (var i = 0; i < ca.length; i++) {
                    var c = ca[i];
                    while (c.charAt(0) == ' ') {
                        c = c.substring(1, c.length);
                    }
                    if (c.indexOf(my_cookie_eq) == 0) {
                        return c.substring(my_cookie_eq.length, c.length);
                    }
                }
                return null;
            }

            $(document).ready(function() {
                $("input").attr('maxlength', '120');

                $(':submit').live('click', function() { // This event fires when a button is clicked



                    if (read_cookie(document.getElementById('linkToAdd').value) === null) {


                        $.ajax
                                ({
                                    type: 'POST',
                                    url: 'requester.php',
                                    encoding: "UTF-8",
                                    dataType: 'json',
                                    async: true,
                                    data: "link=" + document.getElementById('linkToAdd').value,
                                    success: function(data)
                                    {


                                        if (data['success'] === true)
                                        {
                                            set_cookie(document.getElementById('linkToAdd').value, document.getElementById('linkToAdd').value, 1 / 2);
                                            $('#videoArea').html('<iframe width="1000" height="563" src="//www.youtube.com/embed/' + data['videolink'] + '" frameborder="0" allowfullscreen></iframe>'); // Clear areadiv                                       
                                            document.getElementById('shareLink').value = 'http://youtu.be/' + data['videolink'];
                                        } else {

                                            switch (data['errorcode']) {
                                                case 1:
                                                    alert("Inserted link is not a YouTube link.");
                                                    break;
                                                case 2:
                                                    alert("No YouTube link existing witch such ID.");
                                                    break;
                                                case 3:
                                                    alert("Page fault");
                                                    break;

                                            }

                                        }

                                    },
                                    error: function(dataE) {
                                        alert(dataE);
                                    }
                                });


                    } else {

                        alert('You have already inserted that link while the last 12 hours.');
                    }
                    return false; // keeps the page from not refreshing 
                });
            });